/**
 * Copyright &copy; 2012-2014 <a href="https://github.com.jims.base">JeeSite</a> All rights reserved.
 */
package com.jims.master.modules.patient.myRecord.service;

import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;
import com.jims.master.modules.patient.myRecord.dao.CaseEnterHospitalDao;
import com.jims.master.modules.patient.myRecord.entity.CaseDiagnosis;
import com.jims.master.modules.patient.myRecord.entity.CaseEnterHospital;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 用于病历同步中常规入院记录Service
 * @author xueyx
 * @version 2016-07-06
 */
@Service
@Transactional(readOnly = true)
public class CaseEnterHospitalService extends CrudService<CaseEnterHospitalDao, CaseEnterHospital> {

	@Autowired
	private CaseDiagnosisService caseDiagnosisService;
	@Override
    public CaseEnterHospital get(String id) {
		return super.get(id);
	}
	
	@Override
    public List<CaseEnterHospital> findList(CaseEnterHospital caseEnterHospital) {
		return super.findList(caseEnterHospital);
	}
	
	@Override
    public Page<CaseEnterHospital> findPage(Page<CaseEnterHospital> page, CaseEnterHospital caseEnterHospital) {
		return super.findPage(page, caseEnterHospital);
	}
	
	@Override
    @Transactional(readOnly = false)
	public int save(CaseEnterHospital caseEnterHospital) {
		return super.save(caseEnterHospital);
	}
	
	@Override
    @Transactional(readOnly = false)
	public int delete(CaseEnterHospital caseEnterHospital) {
		return super.delete(caseEnterHospital);
	}

	public CaseEnterHospital getEnterByZhuYuan(String zhuyuanId){
		return  dao.getEnterByZhuYuan(zhuyuanId);

	}

	/**
	 * @param caseEnterHospital
	 */
	@Transactional(readOnly = false)
	public void saveHos(CaseEnterHospital caseEnterHospital,CaseDiagnosis caseDiagnosis){
		if(caseEnterHospital.getCaijiRiqi()==null || caseEnterHospital.getCaijiRiqi().equals("")){
			caseEnterHospital.setCaijiRiqi(new Date());
		}
		this.save(caseEnterHospital);//保存入院记录
		caseDiagnosisService.batchSave(caseEnterHospital.getId(),caseDiagnosis.getEmrDiagnosisList());
	}

	public CaseEnterHospital getByClinicId(CaseEnterHospital caseEnterHospital){
		return dao.getByClinicId(caseEnterHospital);
	}

}